package com.z.qyWeixin.dao;

import com.z.qyWeixin.entity.Org;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.z.qyWeixin.vo.OrgVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author z
 * @since 2022-03-29
 */
public interface OrgMapper extends BaseMapper<Org> {

    /**
     * 微信后台所有机构
     * @return
     */
    @Select("SELECT u . NAME, u.id, u.parentid, o. SID orgId, d.code FROM T_USER_WEIXIN_DEPT u LEFT JOIN T_DEPARTID_NUM w on w.num=u.id LEFT JOIN hr_om_org o on o.sid=w.departid LEFT JOIN hr_om_org_detail D ON o.org_detail_id = D . SID ORDER BY d.code")
    List<OrgVO> getWXOrgList();

    /**
     * 本地所有机构
     * @return
     */
    @Select("SELECT n.DEPARTID orgId, if(d.name_abbr_cn, d.name_abbr_cn, D.name) name, n.NUM id,u.parentid,d.code FROM hr_om_org o LEFT JOIN T_DEPARTID_NUM n ON o. SID = n.DEPARTID LEFT JOIN hr_om_org_detail D on D . SID = o.org_detail_id LEFT JOIN T_USER_WEIXIN_DEPT u on u.id=n.num WHERE o.deleted=0 and o.dimension=1 ORDER BY d.code")
    List<OrgVO> getOrgList();

    /**
     * 微信后台无映射关系的机构
     * @return
     */
    @Select("SELECT u . NAME, u.id, u.parentid, o. SID orgId, d.code FROM T_USER_WEIXIN_DEPT u LEFT JOIN T_DEPARTID_NUM w on w.num=u.id LEFT JOIN hr_om_org o on o.sid=w.departid LEFT JOIN hr_om_org_detail D ON o.org_detail_id = D . SID where u.id not in (select num from t_departid_num where ACTIVE=1)ORDER BY d.code")
    List<OrgVO> getWXNOTTOLocalOrgList();


}
